import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets


import App from './App'
import store from './store'
import router from './router'
import dictUtils from '@/utils/dictUtils'

import '@/icons' // icon
import '@/permission' // permission control
import './utils/error-log' // error log
import '@/html-editor'

import * as filters from './filters' // global filters


// 引入table组件
import XEUtils from 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
Vue.use(VXETable)

import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
VXETable.use(VXETablePluginElement)



Vue.prototype.$dictUtils = dictUtils  // 存放各种枚举

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// result.type = success, warning, info, error
Vue.prototype.notify = function (result, content, duration){
  this.$notify.closeAll()

  if (content === undefined) {
    content = result.content
  }
  if (duration === undefined) {
    duration = 4000
  }
  let type = result.type;
  if (this.isNull(type)) {
    type = result.success?'success':'error';
  }
  this.$notify({
    title: result.success?'成功':'失败',
    type,
    message: content,
    duration: duration
  });
}

Vue.prototype.isNull = function (str){
  if (str === null || str === undefined || str.length === 0) {
    return true
  }
  return false
}

//复制到粘贴板插件
import VueClipboard from 'vue-clipboard2'
VueClipboard.config.autoSetContainer = true
Vue.use(VueClipboard)

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

import './assets/style.scss'
import './styles/element-variables.scss'
import '@/styles/index.scss' // global css
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import Element from 'element-ui'
Vue.use(Element, {
  locale,
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

import formCreate from '@form-create/element-ui'
// import FcDesigner from '@form-create/designer'
import FcDesigner from '../src/components/formDesigner/index';

Vue.use(formCreate)
Vue.use(FcDesigner)

// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

import ViewUI from 'view-design';
import 'view-design/dist/styles/iview.css';
import "./styles/taskflow/init.scss"
import JsonViewer from 'vue-json-viewer'
Vue.use(JsonViewer);
import events from "@/utils/taskflow/index";
Vue.prototype.$events = events;
Vue.use(ViewUI);

/*
Vue.component('async-form-detail', function (resolve) {
  // 这个特殊的 `require` 语法将会告诉 webpack
  // 自动将你的构建代码切割成多个包，这些包
  // 会通过 Ajax 请求加载
  require(['@/views/form/template/detail'], resolve)
})
*/


Vue.config.productionTip = false
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})


// 给 vue 实例挂载全局窗口对象
Vue.prototype.$XModal = VXETable.modal

// Vue.prototype.$layer = layer(Vue)

VXETable.setup({
  pager: {
    pageSizes: [10, 20, 50, 100, 200, 500]
  }
})
